typedef void* UNumberFormat

Number Format C API Provides functions for formatting and parsing a number

Documentation

Number Format C API Provides functions for formatting and parsing a number. Also provides methods for determining which locales have number formats, and what their names are.

UNumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. There are different number format styles like decimal, currency, percent and spellout.

To format a number for the current Locale, use one of the static factory methods:

.   UChar myString[20];
.   UFieldPosition pos=0;
.   double myNumber = 7.0;
.   UErrorCode success = ZERO_ERROR;
.   UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, &success)
.   unum_formatDouble(nf, myNumber, myString, u_strlen(myString), &pos, &status);
.   printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.
.    UChar* myString;
.    t_int32 i, resultlength, reslenneeded;
.    UErrorCode success = ZERO_ERROR;
.    UFieldPosition pos=0;
.    t_int32 a[] = { 123, 3333, -1234567 };
.    const t_int32 a_len = sizeof(a) / sizeof(a[0]);
.    UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, &success)
.    for (i = 0; i < a_len; i++) {
.    resultlength=0;
.    reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
.    if(status==BUFFER_OVERFLOW_ERROR){
.        status=ZERO_ERROR;
.        resultlength=resultlengthneeded+1;
.        result=(UChar*)malloc(sizeof(UChar) * resultlength);
.        unum_format(nf, a[i], result, resultlength, &pos, &status);
.    }
.    printf(" Example 2: %s\n", austrdup(result) );
.    free(result);
.    }
To format a number for a different Locale, specify it in the call to unum_open().
.    UNumberFormat* nf = unum_open(UNUM_DEFAULT, "fr_FR", &success)
You can use a NumberFormat API unum_parse() to parse.
.   UErrorCode success;
.   t_int32 pos=0;
.   unum_parse(nf, result, u_strlen(result), &pos, &success);
Use UCAL_DECIMAL to get the normal number format for that country. There are other static options available. Use UCAL_CURRENCY to get the currency number format for that country. Use UCAL_PERCENT to get a format for displaying percentages. With this format, a fraction from 0.53 is displayed as 53%.

You can also control the display of numbers with such function as unum_getAttribues() and unum_setAtributes(). where in you can set the miminum fraction digits, grouping used etc.

See Also:
UNumberFormatAttributes for more details

You can also use forms of the parse and format methods with ParsePosition and UFieldPosition to allow you to:

It is also possible to change or set the symbols used for a particular locale like the currency symbol, the grouping seperator , monetary seperator etc by making use of functions unum_setSymbols() and unum_getSymbols().

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de